-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Predicate for authorizationConsentRequired for device code grant #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Predicate for authorizationConsentRequired for device code grant #2048
Conversation
1bfbd37
to
9f0dfc6
Compare
Previously, device consent handling did not provide a dedicated context for device verification authentication flows. This commit introduces OAuth2DeviceVerificationAuthenticationContext and updates related providers and tests to enhance device authorization and consent flows. Fixes spring-projectsgh-1965 Signed-off-by: Dinesh Gupta <[email protected]> Add Predicate for authorizationConsentRequired for device code grant Introduce a customizable Predicate to determine whether user authorization consent is required in the Device Code grant flow. This enhancement allows applications to define custom logic for skipping or displaying the consent page, enabling greater flexibility to handle cases where user code confirmation and scope approval may be decoupled. The default behavior is preserved, but can be overridden by calling OAuth2DeviceVerificationAuthenticationProvider#setAuthorizationConsentRequired(Predicate). Closes: spring-projectsgh-1965 Signed-off-by: Dinesh Gupta <[email protected]> Add Predicate for authorizationConsentRequired for device code grant This commit introduces a Predicate extension point for determining if user consent is required during the OAuth 2.0 Device Authorization Grant (device code flow). - Adds OAuth2DeviceVerificationAuthenticationContext to provide context to the Predicate - Updates OAuth2DeviceVerificationAuthenticationProvider to support a custom Predicate via setAuthorizationConsentRequired - Refactors default consent logic to use the Predicate - Updates and adds tests for custom Predicate behavior Closes spring-projectsgh-1965 Signed-off-by: Dinesh Gupta <[email protected]> Refactor DeviceVerification context to align with code grant context Refactored OAuth2DeviceVerificationAuthenticationContext to use a map-based structure consistent with OAuth2AuthorizationCodeRequestAuthenticationContext. Aligned method signatures, builder pattern, and attribute handling for consistency and extensibility. Updated OAuth2DeviceVerificationAuthenticationProvider to use the revised context and normalize requested scopes. Closes spring-projectsgh-1965-device-consent Authored-by: Dinesh Gupta <[email protected]> Align device verification consent logic with code grant context Refactored OAuth2DeviceVerificationAuthenticationProvider and its tests to ensure the device verification consent logic and structure are consistent with the authorization code flow. Improved test consistency, predicate usage, and aligned context handling for maintainability. Closes spring-projectsgh-1965-device-consent Authored-by: Dinesh Gupta <[email protected]> Clarify Javadoc for device consent predicate Closes spring-projectsgh-1965-device-consent Authored-by: Dinesh Gupta <[email protected]> Signed-off-by: Dinesh Gupta <[email protected]> Fix test cases for device code consent predicate Cleaned up and improved consistency of test cases related to the device code authorizationConsentRequired predicate. Signed-off-by: Dinesh Gupta <[email protected]>
9f0dfc6
to
e16d62e
Compare
Thanks for the PR @dineshgupta630. I will review this soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @dineshgupta630. Please see review comments.
Also, can you please update the commit message to be a shorter summary of the changes. Thanks.
* </p> | ||
* @param authorizationConsentRequired the {@code Predicate} used to determine if | ||
* authorization consent is required for device verification | ||
* @since 2.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to 2.0
@@ -0,0 +1,185 @@ | |||
/* | |||
* Copyright 2025 the original author or authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update copyright year -> 2020-2025
* determining if authorization consent is required. | ||
* | ||
* @author Dinesh Gupta | ||
* @since 2.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to 2.0
@SuppressWarnings("unchecked") | ||
@Nullable | ||
@Override | ||
public <T extends Authentication> T getAuthentication() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed as the default
method in OAuth2AuthenticationContext
is the same.
/** | ||
* A builder for {@link OAuth2DeviceVerificationAuthenticationContext}. | ||
*/ | ||
public static final class Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builder
should extend AbstractBuilder
, see OAuth2AuthorizationCodeRequestAuthenticationContext
for example
* Returns the {@link OAuth2Authorization authorization}. | ||
* @return the {@link OAuth2Authorization}, or {@code null} if not available | ||
*/ | ||
@Nullable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OAuth2Authorization
should never be null
Set<String> requestedScopes = authorization.getAttribute(OAuth2ParameterNames.SCOPE); | ||
authenticationContextBuilder.requestedScopes(requestedScopes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to provide requestedScopes()
since OAuth2Authorization
is supplied in the context and it contains request scopes via authorization.getAttribute(OAuth2ParameterNames.SCOPE)
.
Adds a pluggable predicate to control whether consent is required in the device code grant flow . Fixes #1965
Notes: No breaking changes; the predicate is opt-in.